package org.wheel.plugins.toolkit.sql.core;

import org.wheel.plugins.toolkit.sql.enums.Dialect;
import org.wheel.plugins.toolkit.sql.enums.SqlModel;
import org.wheel.plugins.toolkit.sql.page.PaginationStrategy;
import org.wheel.plugins.toolkit.sql.page.PaginationStrategyFactory;
import org.wheel.plugins.toolkit.sql.page.impl.PaginationStrategyFactoryImpl;

public class GlobalConfig {

    private static final ThreadLocal<Dialect> DIALECT = ThreadLocal.withInitial(() -> Dialect.MYSQL);
    private static final ThreadLocal<SqlModel> SQL_MODEL = ThreadLocal.withInitial(SqlModel::getDefaultModel);
    // 内置默认分页策略
    private static final PaginationStrategyFactory paginationStrategyFactory = new PaginationStrategyFactoryImpl();

    public static void setSqlModel(SqlModel m) {
        SQL_MODEL.set(m);
    }
    public static SqlModel getSqlModel() {
        return SQL_MODEL.get();
    }

    public static void setDialect(Dialect d) {
        DIALECT.set(d);
    }

    public static Dialect getDialect() {
        return DIALECT.get();
    }

    public static PaginationStrategy getDefaultPaginationStrategy(){
        return paginationStrategyFactory.createPaginationStrategy(getDialect());
    }
}
